package com.quanyan.video.repository;

import com.quanyan.common.exception.BizException;
import com.quanyan.video.emun.VideoErrorEnum;
import com.quanyan.video.entity.Project;
import com.quanyan.video.entity.ProjectExample;
import com.quanyan.video.mapper.ProjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by wmb on 2016/6/27.
 */
@Repository
public class ProjectRepository {
    @Autowired
    private ProjectMapper projectMapper;
    public Project selectByName(String projectName) {
        ProjectExample projectExample=new ProjectExample();
        projectExample.createCriteria().andNameEqualTo(projectName);
        List<Project> projectList=projectMapper.selectByExample(projectExample);
        if(projectList.isEmpty()){
            throw new BizException(VideoErrorEnum.PROJECT_NOT_EXIST);
        }else{
            return projectList.get(0);
        }
    }

    public Integer insertSelective(Project project) {
        projectMapper.insertSelective(project);
        return project.getId();
    }
}
